/*
	Name:【模板】LCA
	Author: There,hello 
	Date: 25-10-19 13:00
	Description: Luogu P3379
	Algorithm: 用树链剖分求lca
*/
#include<bits/stdc++.h>
using namespace std;
#define add(x,y) edge[++tail]=(dd){head[x],y};head[x]=tail;
int n,m,root_;
int head[501010],tail,deep[501010],fa[501010];
int son[501010],size_[501010],fir[501010];
struct dd{
    int ne,to;
}edge[1002020];
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while (ch>='0'&&ch<='9'){
        x=x*10+(ch^48);
        ch=getchar();
    }
    return f*x;
}
void dfs1(int t,int faa,int depth){
    deep[t]=depth;
    fa[t]=faa;
    size_[t]=1;
    for(int i=head[t];i;i=edge[i].ne){
        int to=edge[i].to;
        if(to==faa)continue;
        dfs1(to,t,depth+1);
        size_[t]+=size_[to];
        if(size_[to]>size_[son[t]])son[t]=to;
    }
}
void dfs2(int t,int fir_){
    fir[t]=fir_;
    if(!son[t])return;
    dfs2(son[t],fir_);
    for(int i=head[t];i;i=edge[i].ne){
        if(!fir[edge[i].to]){
            dfs2(edge[i].to,edge[i].to);
        }
    }
}
inline int lca(int x,int y){
    while(fir[x]!=fir[y]){
        if(deep[fir[x]]<deep[fir[y]])swap(x,y);
        x=fa[fir[x]];
    }
    return deep[x]<deep[y]?x:y;
}
int main(){
    scanf("%d%d%d",&n,&m,&root_);
    for(int i=1,x,y;i<n;++i){
        x=read();y=read();
        add(x,y);add(y,x);
    }
    dfs1(root_,root_,1);
    dfs2(root_,root_);
    for(int i=1,x,y;i<=m;++i){
        x=read();y=read();
        printf("%d\n",lca(x,y));
    }
}